/*

	Copyright 2010 Anatol Gregory Mayen
	
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
 
	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

package eu.maydu.gwt.gxtcomponents.client.password;

import java.util.LinkedList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModelData;

import eu.maydu.gwt.gxtcomponents.client.password.PasswordStrengthRule.RuleClass;
import eu.maydu.gwt.gxtcomponents.client.password.i18n.PasswordI18n;

/**
 * 
 * This class acts as a holder class for using it in
 * GXT's template functionality.
 * 
 * @author Anatol Mayen
 * 16.03.2010
 */
public class UnfulfilledPasswordStrengthRules extends BaseModelData {
	
	
	
	public UnfulfilledPasswordStrengthRules(List<PasswordStrengthRule> rules, PasswordI18n i18n) {
		List<UnfulfilledPasswordStrengthRuleModelData> rulesModelData = new LinkedList<UnfulfilledPasswordStrengthRuleModelData>();
		for(PasswordStrengthRule r : rules)
			rulesModelData.add(new UnfulfilledPasswordStrengthRuleModelData(r.getRuleClass(), r.getRuleFulfilledCount(), i18n));
		
		set("rules", rulesModelData);
		set("ruleDescriptionHeader", i18n.passwordStrengthIndicatorRuleDescriptionHeader());
		set("ruleCharacterSetHeader", i18n.passwordStrengthIndicatorRuleCharacterSetHeader());
		set("ruleMinCountHeader", i18n.passwordStrengthIndicatorRuleMinCountHeader());
	}
	

	public class UnfulfilledPasswordStrengthRuleModelData extends BaseModelData {
		public UnfulfilledPasswordStrengthRuleModelData(RuleClass c, int minCount, PasswordI18n i18n) {
			String description = "";
			String charSet = "";
			if(RuleClass.ALPHABET_UPPERCASE == c) {
				description = i18n.passwordStrengthIndicatorRuleAlphabetUpperCaseDescription();
				charSet = "A-Z";
			}else if(RuleClass.ALPHABET_LOWERCASE == c) {
				description = i18n.passwordStrengthIndicatorRuleAlphabetLowerCaseDescription();
				charSet = "a-z";
			}
			else if(RuleClass.ALPHABET_IGNORECASE == c) {
				description = i18n.passwordStrengthIndicatorRuleAlphabetIgnoreCaseDescription();
				charSet = "a-z, A-Z";
			}else if(RuleClass.NUMBERS == c) {
				description = i18n.passwordStrengthIndicatorRuleNumbersDescription();
				charSet = "0-9";
			}else if(RuleClass.SIGNS == c) {
				description = i18n.passwordStrengthIndicatorRuleSignsDescription();
				charSet = "!\"§$%&/()=?`´*'_:;{[]}\\~,.-#+";
			}else if(RuleClass.PASSWORD_LENGTH == c) {
				description = i18n.passwordStrengthIndicatorRulePasswordLengthDescription();
				charSet = "";
			}
			
			set("description", description);
			set("charSet", charSet);
			set("minCount", minCount);
		}
	}
	
}
